// DISCORD
if ("discord.com" == window.location.host) {
  console.log("Discord");

  // 创建一个按钮元素
  const button = document.createElement("button");
  // button.textContent = "Discord 增强";
  button.style.title = "Discord 增强";
  button.style.alter = "Discord 增强";
  button.style.position = "fixed";
  button.style.width = "32px";
  button.style.height = "32px";
  button.style.bottom = "20px";
  button.style.right = "20px";
  button.style.zIndex = 1000;
  button.style.color = "#fff";
  button.style.border = "none";
  button.style.borderRadius = "50%";
  button.style.cursor = "pointer";
  button.style.backgroundImage = `url(${chrome.runtime.getURL("discord.jpg")})`;
  button.style.backgroundSize = "cover"; // 背景图片覆盖整个按钮
  button.style.backgroundPosition = "center"; // 背景图片居中
  button.style.backgroundColor = "#007bff";
  button.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.3)"; // 添加阴影

  // 创建一个文字提示元素
  const tooltip = document.createElement("div");
  tooltip.textContent = "Discord 增强";
  tooltip.style.position = "fixed";
  tooltip.style.bottom = "60px"; // 提示文字位于按钮上方
  tooltip.style.right = "20px";
  tooltip.style.backgroundColor = "rgba(0, 0, 0, 0.8)";
  tooltip.style.color = "#fff";
  tooltip.style.padding = "8px 12px";
  tooltip.style.borderRadius = "4px";
  tooltip.style.fontSize = "14px";
  tooltip.style.display = "none"; // 默认隐藏
  tooltip.style.zIndex = 1001; // 确保提示文字在按钮上方
  tooltip.style.boxShadow = "0 2px 4px rgba(0, 0, 0, 0.2)"; // 提示文字阴影

  button.style.opacity = 0.3;
  // 添加鼠标悬停效果（可选）
  button.addEventListener("mouseenter", () => {
    button.style.opacity = 1; // 鼠标悬停时完全不透明
    tooltip.style.display = "block"; // 显示提示文字
  });
  button.addEventListener("mouseleave", () => {
    button.style.opacity = 0.3; // 鼠标离开时恢复半透明
    tooltip.style.display = "none"; // 隐藏提示文字
  });

  // 添加点击事件
  button.addEventListener("click", () => {
    const token = localStorage.getItem("token").replace(/^"|"$/g, "");
    const inputToken = document.getElementById("input-token");
    inputToken.value = token;

    const infoShow = document.getElementById("info-show");
    const infoShowDisplay = infoShow.style.display;
    infoShow.style.display = infoShowDisplay == "block" ? "none" : "block";
  });

  // 将按钮添加到页面上
  document.body.appendChild(button);
  document.body.appendChild(tooltip);
  createInfoContent();
}

function createInfoContent() {
  // 创建一个文字提示元素
  const infoShow = document.createElement("div");
  infoShow.id = "info-show";
  infoShow.style.position = "fixed";
  infoShow.style.bottom = "120px";
  infoShow.style.right = "20px";
  infoShow.style.width = "640px";
  infoShow.style.backgroundColor = "white";
  infoShow.style.color = "#000";
  infoShow.style.padding = "8px 12px";
  infoShow.style.borderRadius = "4px";
  infoShow.style.fontSize = "14px";
  infoShow.style.display = "none";
  infoShow.style.zIndex = 1001;
  infoShow.style.boxShadow = "0 2px 4px rgba(0, 0, 0, 0.2)";
  document.body.appendChild(infoShow);

  const titleToken = document.createElement("span");
  titleToken.style.color = "#000";
  titleToken.textContent = "Token: ";
  infoShow.appendChild(titleToken);

  const inputToken = document.createElement("input");
  inputToken.id = "input-token";
  inputToken.style.width = "540px";
  infoShow.appendChild(inputToken);

  const copyBtn = document.createElement("button");
  copyBtn.style.color = "#000";
  copyBtn.style.border = "none";
  copyBtn.style.borderRadius = "5px";
  copyBtn.style.backgroundColor = "rgb(133 173 215)";
  copyBtn.style.marginLeft = "5px";
  copyBtn.style.boxShadow = "0 4px 8px rgba(0, 0, 0, 0.3)"; // 添加阴影
  copyBtn.textContent = "复制";
  // 复制按钮点击事件
  copyBtn.addEventListener("click", () => {
    // 选中并复制文本
    inputToken.select();
    document.execCommand("copy");
    // 可选：显示复制成功的消息
    swal({
		title: "成功!",
		text: "已把 Token 复制到剪切板",
		timer: 3000, // 10秒倒计时
		showConfirmButton: false // 不显示确认按钮
	  });
  });

  infoShow.appendChild(copyBtn);
}
